
var host = 'https://service.zehuiwenhua.com/'
// $('#inputUsername').blur(function() {
//     var reg = /^[0-9a-zA-Z]*$/g; //判断字符串是否为数字和字母组合     //判断正整数 /^[1-9]+[0-9]*]*$/    
//     if (!reg.test($('#inputUsername').val())) {
//         $('.registerMes').html("账号只能为数字和字母组合");
//     } else {
//         $('.registerMes').html("  &nbsp;");

//     }
// })
$('#zhuce').click(function() {
   
    $.ajax({
        url: host + 'service/website/register',
        type: "post",
        data: { "username": $("#inputUsername").val(), "pwd": $("#inputPassword").val() },
        success: function(resp) {

           
            if (resp.code == "000") {
                $('#register').modal('hide');
                $('#login').modal('show');

            } else if (resp.code == "001") {
                $('.registerMes').html(resp.msg);
            } else {
                $('.registerMes').html(resp.msg);
            }
        }


    })
})
$('#register').on('hidden.bs.modal', function (e) {
   $("#inputUsername").val('');
   $("#inputPassword").val('');
    $('.registerMes').html("&nbsp;");
})

$('#denglu').click(function() {
    var url = 'http://purk-win10:8080/service/website/login';
    
    $.ajax({
        url: host + 'service/website/login',
        type: "post",
        data: { "username": $("#loginUsername").val(), "pwd": $("#loginPassword").val() },
        success: function(resp) {

           
            if (resp.code == "000") {
                localStorage.setItem('username', resp.data.username);
                $('#login').modal('hide');
                $("#usernameLink").html(resp.data.username);
                $("[section='NotloginSection']").hide();
                $("[section='loginSection']").show();

            } else if (resp.code == "001") {
                // 001 密码不正确
                $('.loginmsg').html(resp.msg);
            } else {
                $('.loginmsg').html(resp.msg);
            }

        }
    })
})

$('#login').on('hidden.bs.modal', function (e) {
   $("#loginUsername").val('');
   $("#loginPassword").val('')
    $('.loginmsg').html("&nbsp; ");
})

$('#logout').click(function() {
    localStorage.removeItem('username');
    $("[section='NotloginSection']").show();
    $("[section='loginSection']").hide();
})

$('#payment').click(function () {
    $.ajax({
        url: host + 'service/website/payment',
        type: "post",
        data: { "mobile": $("#mobile").val(), "price": 1980.00, "username": localStorage.getItem('username') },
        success: function (resp) {

            $(".waiting").show();
            $('#payment').attr("disabled", true);
            if (resp.code == "000") {
                $('.Paymentmsg').html(' ');
                $('.waiting').hide();
              
                $('#payment').html('购买成功');
                setTimeout(function () {
                    $('#buy').modal('hide');
                    $('#payment').attr("disabled", false);
                }, 2000)
            } else if (resp.code == "001") {
                // 001 密码不正确
                $('.Paymentmsg').html(resp.msg);
                $('.waiting').hide();
                $('#payment').attr("disabled", false);
            } else {
                $('.Paymentmsg').html(resp.msg);
                $('.waiting').hide();
                $('#payment').attr("disabled", false);
            }
        }
    })
})

$('#buy').on('show.bs.modal', function(e) {
    if (localStorage.getItem('username')) {
        return true;
    } else {
        $('#login').modal('show');
        return false;
    }
})


$('#buy').on('hidden.bs.modal', function (e) {
   $('#payment').html('确认支付');
   $('.Paymentmsg').html('');
    $('#mobile').val('');
})

$(document).ready(function() {
    if (localStorage.getItem('username')) {
        $("#usernameLink").html(localStorage.getItem('username'));
        $("[section='NotloginSection']").hide();
        $("[section='loginSection']").show();
    } else {
        $("[section='NotloginSection']").show();
        $("[section='loginSection']").hide();
    }
});


$('.link-a>a').click(function() {
    console.log('click')
    if ($(this).html() == "注册") {
        $('#login').modal('hide');
        $('#register').modal('show');
    } else {
        $('#register').modal('hide');
        $('#login').modal('show');
    }
})